//
//  LXMusicPlayerVC.m
//  喜马拉雅改良版框架
//
//  Created by liuxin on 15/12/24.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "LXMusicPlayerVC.h"
#import "LXMusicPlayModel.h"
#import "LXHistoryViewController.h"
#import "LXMusicPlayerListVC.h"
#import "CoreDataManager.h"
#import "MusicDB.h"
@interface LXMusicPlayerVC ()
@property(nonatomic,strong)UIImageView *headImage;
@property(nonatomic,strong)UIImageView *midImage;
@property(nonatomic,strong)UIImageView *logo;
@property(nonatomic,strong)UILabel *titleDetailLabel;
@property(nonatomic,strong)UILabel *voiceLabel;
@property(nonatomic,strong)UILabel *personDescribe;
@property(nonatomic,strong)UILabel *currentTime;
@property(nonatomic,strong)UILabel *totalTime;
@property(nonatomic,strong)UISlider *musicSlider;
@property(nonatomic,strong)NSTimer *playTimer;
@property(nonatomic,retain)NSManagedObjectContext *managerObjectContext;
@end

@implementation LXMusicPlayerVC
-(void)viewWillAppear:(BOOL)animated{
    self.navigationController.navigationBar.hidden =YES;
    if ([[[LXMusicPlay shareLXMusicPlay]isPlayOrStop]isEqualToString:@"continue"]) {
        [self.playButton setImage:[UIImage imageNamed:@"toolbar_pause_n_p@2x.png"] forState:UIControlStateNormal];
    }else if([[[LXMusicPlay shareLXMusicPlay]isPlayOrStop]isEqualToString:@"stop"]){
        [self.playButton setImage:[UIImage imageNamed:@"toolbar_play_n_p@2x.png"] forState:UIControlStateNormal];
    }
}
-(void)viewWillDisappear:(BOOL)animated{
    self.navigationController.navigationBar.hidden = NO;
    self.navigationController.navigationBar.translucent = NO;
}
+(instancetype)sharaMusicPlayer{
    static LXMusicPlayerVC *playerVC = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        playerVC = [[LXMusicPlayerVC alloc] init];
    });
    return playerVC;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    _managerObjectContext = [[CoreDataManager shareManager]managedObjectContext];
    NSLog(@"%@",[[CoreDataManager shareManager]applicationDocumentsDirectory]);
    self.view.backgroundColor = [UIColor whiteColor];
    self.playTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(Stack) userInfo:nil repeats:YES];
    [self createImageView];
    [self play];
    [self getData];
}
-(void)insertIntoDB{
    NSString *result = [self select];
    if ([result isEqualToString:@"noexist"]) {
        MusicDB *music = [NSEntityDescription insertNewObjectForEntityForName:@"MusicDB" inManagedObjectContext:_managerObjectContext];
        music.title = self.Title;
        music.headImage = self.headImageLarge;
        music.songID = [NSString stringWithFormat:@"%ld",self.songId];
        music.totalTime = [NSString stringWithFormat:@"%ld",self.totaltime];
        music.albumTitle = self.subTitle;
        [[CoreDataManager shareManager]  saveContext];
    }
}

-(NSString*)select{
    NSString *result = @"noexist";
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"MusicDB" inManagedObjectContext:_managerObjectContext];
    [fetchRequest setEntity:entity];
    NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"title"
                                                                   ascending:YES];
    [fetchRequest setSortDescriptors:[NSArray arrayWithObjects:sortDescriptor, nil]];
    NSError *error = nil;
    NSArray *fetchedObjects = [_managerObjectContext executeFetchRequest:fetchRequest error:&error];
    if (fetchedObjects == nil) {
        NSLog(@"%@",error);
    }
    NSMutableArray *MusicDBArr = [NSMutableArray arrayWithArray:fetchedObjects];
    NSString *temp = [NSString stringWithFormat:@"%ld",self.songId];
    if (MusicDBArr.count == 0) {
        result = @"noexist";
    }else{
        for (MusicDB *tempArray in MusicDBArr) {
            if ([tempArray.songID isEqualToString:temp]) {
                result = @"exist";
            }
        }
    }
    return result;
}
-(void)Stack{
    if ([[[LXMusicPlay shareLXMusicPlay]progress] isEqualToString:@"finish"]) {
    }else{
        self.currentTime.text =  [[LXMusicPlay shareLXMusicPlay]progress];
    }
    self.musicSlider.value = [[LXMusicPlay shareLXMusicPlay]SliderValue];
}
-(void)getData{
    NSString *musicUrl = [NSString stringWithFormat:@"http://mobile.ximalaya.com/mobile/track/detail?device=iPhone&trackId=%ld", self.songId];
    [AFNetworkTool getUrl:musicUrl body:nil result:HXJSON headerFile:nil success:^(id result) {
        LXMusicPlayModel *model = [[LXMusicPlayModel alloc]init];
        [model setValuesForKeysWithDictionary:result];
        [self.logo sd_setImageWithURL:[NSURL URLWithString:model.userInfo[@"smallLogo"]] placeholderImage:[UIImage imageNamed:ImagePlaceHolder]];
        self.titleDetailLabel.text = model.userInfo[@"nickname"];
        self.voiceLabel.text = [NSString stringWithFormat:@"声音：%@  粉丝：%@",model.userInfo[@"tracks"],model.userInfo[@"followers"]];
        self.personDescribe.text = model.userInfo[@"personDescribe"];
    } failure:^(NSError *error) {
    }];
}
-(void)createImageView{
    _headImage = [[UIImageView alloc]init];
    _headImage.backgroundColor = [UIColor grayColor];
    _headImage.userInteractionEnabled = YES;
    [_headImage sd_setImageWithURL:[NSURL URLWithString:self.headImageLarge] placeholderImage:[UIImage imageNamed:ImagePlaceHolder]];
    [self.view addSubview:_headImage];
    [_headImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.mas_equalTo(0);
        make.height.mas_equalTo(SCREEN_WIDTH+6+(SCREEN_HEIGHT-SCREEN_WIDTH)/3);
    }];
    
    UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
    UIVisualEffectView *blurView = [[UIVisualEffectView alloc]initWithEffect:effect];
    blurView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_WIDTH+(SCREEN_HEIGHT-SCREEN_WIDTH)/3+10);
    [_headImage addSubview:blurView];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setBackgroundImage:[UIImage imageNamed:@"playingback@2x.png"] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(btnAction) forControlEvents:UIControlEventTouchUpInside];
    [_headImage addSubview:button];
    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(25);
        make.left.mas_equalTo(15);
        make.width.mas_equalTo(25);
        make.height.mas_equalTo(25);
    }];
    
    NSInteger timesec = self.totaltime/60;
    NSInteger timemin = self.totaltime - timesec*60;
    NSString *timeSec = @"";
    NSString *timeMin = @"";
    if (timesec < 10) {
        timeSec = [NSString stringWithFormat:@"0%ld",timesec];
    }else{
        timeSec = [NSString stringWithFormat:@"%ld",timesec];
    }
    if (timemin < 10) {
        timeMin = [NSString stringWithFormat:@"0%ld",timemin];
    }else{
        timeMin = [NSString stringWithFormat:@"%ld",timemin];
    }
    NSString *time = [NSString stringWithFormat:@"%@:%@",timeSec,timeMin];
    self.totalTime = [[UILabel alloc]init];
    self.totalTime.text = time;
    self.totalTime.textAlignment = NSTextAlignmentRight;
    self.totalTime.textColor = [UIColor lightGrayColor];
    [self.headImage addSubview:self.totalTime];
    [self.totalTime mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.right.mas_equalTo(-8);
        make.height.mas_equalTo(20);
        make.width.mas_equalTo(50);
    }];
    
    self.currentTime = [[UILabel alloc]init];
    self.currentTime.text = @"00:00";
    self.currentTime.textColor = [UIColor lightGrayColor];
    [self.headImage addSubview:self.currentTime];
    [self.currentTime mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.bottom.mas_equalTo(-8);
        make.height.mas_equalTo(20);
        make.width.mas_equalTo(50);
    }];
    
    self.backScrollView = [[UIScrollView alloc]init];
    self.backScrollView.bounces = NO;
    self.backScrollView.showsHorizontalScrollIndicator = NO;
    [self.headImage addSubview:self.backScrollView];
    [self.backScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(button.mas_top);
        make.left.equalTo(button.mas_right).offset(10);
        make.right.mas_equalTo(-55);
        make.height.mas_equalTo(25);
    }];
    
    CGSize titleLabelSize = [AppTools labelRectWithLabelSize:CGSizeMake(1000, 25) LabelText:self.Title Font:[UIFont systemFontOfSize:17]];
    if (titleLabelSize.width < (SCREEN_WIDTH-25-25-15-15-10-10)) {
        self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, (SCREEN_WIDTH-25-25-15-15-10-10), 25)];
    }else{
        self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, titleLabelSize.width, 25)];
    }
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    self.titleLabel.text = self.Title;
    self.titleLabel.textColor = [UIColor whiteColor];
    [self.backScrollView addSubview:self.titleLabel];
    self.backScrollView.contentSize = CGSizeMake(titleLabelSize.width, 25);
    
    
    UIButton *more = [UIButton buttonWithType:UIButtonTypeCustom];
    [more setBackgroundImage:[UIImage imageNamed:@"icon_more@2x.png"] forState:UIControlStateNormal];
    [_headImage addSubview:more];
    [more addTarget:self action:@selector(moreAction) forControlEvents:UIControlEventTouchUpInside];
    [more mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(button.mas_top);
        make.right.mas_equalTo(-15);
        make.height.mas_equalTo(25);
        make.left.equalTo(self.backScrollView.mas_right).offset(10);
    }];
    
    self.midImage = [[UIImageView alloc]init];
    [self.midImage sd_setImageWithURL:[NSURL URLWithString:self.headImageLarge] placeholderImage:[UIImage imageNamed:ImagePlaceHolder]];
    [self.headImage addSubview:self.midImage];
    [self.midImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(50);
        make.right.mas_equalTo(-50);
        make.top.equalTo(more.mas_bottom).offset(50);
        make.bottom.equalTo(self.headImage.mas_bottom).offset(-70);
    }];
    UIView *slider = [[UIView alloc]init];
    slider.backgroundColor = [UIColor colorWithWhite:0.835 alpha:1.000];
    [self.view addSubview:slider];
    [slider mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.equalTo(_headImage.mas_bottom);
        make.height.mas_equalTo(5);
    }];
    //    音乐进度条
    self.musicSlider = [[UISlider alloc]init];
    self.musicSlider.maximumValue  =self.totaltime;
    self.musicSlider.value = 0;
    self.musicSlider.tintColor = [UIColor colorWithRed:1 green:0.34 blue:0.07 alpha:1];
    [self.musicSlider setThumbImage:[UIImage imageNamed:@"playProcessDot_n@3x"] forState:UIControlStateNormal];
    [self.musicSlider addTarget:self action:@selector(musicSliderAction:) forControlEvents:UIControlEventValueChanged];
    [slider addSubview:self.musicSlider];
    [self.musicSlider mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(slider);
    }];
    
    UIView *playView = [[UIView alloc]init];
    [self.view addSubview:playView];
    [playView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(slider.mas_bottom);
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo((SCREEN_HEIGHT-SCREEN_WIDTH)/3-20);
    }];
    
    self.playButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.playButton setBackgroundImage:[UIImage imageNamed:@"toolbar_loading_n_p@2x.png"] forState:UIControlStateNormal];
    if ([[[LXMusicPlay shareLXMusicPlay]isPlayOrStop] isEqualToString:@"stop"]) {
        [self.playButton setImage:[UIImage imageNamed:@"toolbar_pause_n_p@2x.png"] forState:UIControlStateNormal];
    }else{
        [self.playButton setImage:[UIImage imageNamed:@"toolbar_play_n_p@2x.png"] forState:UIControlStateNormal];
    }
    [self.playButton addTarget:self action:@selector(playAction) forControlEvents:UIControlEventTouchUpInside];
    [playView addSubview:self.playButton];
    [self.playButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(10);
        make.centerX.equalTo(self.view.mas_centerX);
        make.width.mas_equalTo((SCREEN_HEIGHT-SCREEN_WIDTH)/3-40);
        make.bottom.mas_equalTo(-10);
    }];
    
    self.frontButton = [UIButton buttonWithType:UIButtonTypeCustom];
    if (self.index == 0) {
        [self.frontButton setBackgroundImage:[UIImage imageNamed:@"toolbar_prev_h_p@2x.png"] forState:UIControlStateNormal];
        self.frontButton.enabled = NO;
    }else{
        [self.frontButton setBackgroundImage:[UIImage imageNamed:@"toolbar_prev_n_p@2x.png"] forState:UIControlStateNormal];
    }
    [self.frontButton addTarget:self action:@selector(frontButtonAction) forControlEvents:UIControlEventTouchUpInside];
    [playView addSubview:self.frontButton];
    [self.frontButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.playButton.mas_left).offset(-25);
        make.top.mas_equalTo(15);
        make.bottom.mas_equalTo(-15);
        make.width.mas_equalTo((SCREEN_HEIGHT-SCREEN_WIDTH)/3-50);
    }];
    
    self.nextButton = [UIButton buttonWithType:UIButtonTypeCustom];
    if (self.index == self.allArray.count) {
        [self.nextButton setBackgroundImage:[UIImage imageNamed:@"toolbar_next_d_p@2x.png"] forState:UIControlStateNormal];
        self.nextButton.enabled = NO;
    }else{
        [self.nextButton setBackgroundImage:[UIImage imageNamed:@"toolbar_next_n_p@2x.png"] forState:UIControlStateNormal];
    }
    [self.nextButton addTarget:self action:@selector(nextButtonAction) forControlEvents:UIControlEventTouchUpInside];
    [playView addSubview:self.nextButton];
    [self.nextButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.playButton.mas_right).offset(25);
        make.top.mas_equalTo(15);
        make.bottom.mas_equalTo(-15);
        make.width.mas_equalTo((SCREEN_HEIGHT-SCREEN_WIDTH)/3-50);
    }];
    
    UIButton *playList = [UIButton buttonWithType:UIButtonTypeCustom];
    [playList setBackgroundImage:[UIImage imageNamed:@"toolbar_playinglist_n_p@2x.png"] forState:UIControlStateNormal];
    [playList addTarget:self action:@selector(playListAction) forControlEvents:UIControlEventTouchUpInside];
    [playView addSubview:playList];
    [playList mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(0);
        make.right.equalTo(self.frontButton.mas_left).offset(-5);
        make.width.mas_equalTo((SCREEN_HEIGHT-SCREEN_WIDTH)/3-30);
    }];
    
    UIButton *history = [UIButton buttonWithType:UIButtonTypeCustom];
    [history setBackgroundImage:[UIImage imageNamed:@"toolbar_history_n_p@2x.png"] forState:UIControlStateNormal];
    [history addTarget:self action:@selector(historyAction) forControlEvents:UIControlEventTouchUpInside];
    [playView addSubview:history];
    [history mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(0);
        make.left.equalTo(self.nextButton.mas_right).offset(5);
        make.width.mas_equalTo((SCREEN_HEIGHT-SCREEN_WIDTH)/3-30);
    }];
    UIView *spaceView = [[UIView alloc]init];
    spaceView.backgroundColor = [UIColor colorWithWhite:0.835 alpha:1.000];
    [self.view addSubview:spaceView];
    [spaceView mas_makeConstraints:^(MASConstraintMaker *make){
        make.left.right.mas_equalTo(0);
        make.top.equalTo(playView.mas_bottom);
        make.height.mas_equalTo(10);
    }];
    
    UIView *infoView = [[UIView alloc]init];
    [self.view addSubview:infoView];
    [infoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(-5);
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo((SCREEN_HEIGHT-SCREEN_WIDTH)/3);
    }];
    
    self.logo = [[UIImageView alloc]init];
    self.logo.layer.cornerRadius =((SCREEN_HEIGHT-SCREEN_WIDTH)/3 - 20)/2;
    self.logo.layer.masksToBounds = YES;
    [infoView addSubview:self.logo];
    [self.logo mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(10);
        make.bottom.mas_equalTo(-10);
        make.left.mas_equalTo(10);
        make.width.mas_equalTo((SCREEN_HEIGHT-SCREEN_WIDTH)/3 - 20);
    }];
    
    self.titleDetailLabel = [[UILabel alloc]init];
    [infoView addSubview:self.titleDetailLabel];
    [self.titleDetailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.logo.mas_right).offset(10);
        make.right.mas_equalTo(-10);
        make.height.mas_equalTo(25);
        make.top.mas_equalTo(10);
    }];
    
    self.voiceLabel = [[UILabel alloc]init];
    self.voiceLabel.textColor = [UIColor lightGrayColor];
    self.voiceLabel.font = [UIFont systemFontOfSize:15];
    [infoView addSubview:self.voiceLabel];
    [self.voiceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleDetailLabel.mas_bottom).offset(5);
        make.left.equalTo(self.logo.mas_right).offset(10);
        make.height.mas_equalTo(((SCREEN_HEIGHT-SCREEN_WIDTH)/3-30-25)/2);
        make.right.mas_equalTo(-10);
    }];
    
    self.personDescribe = [[UILabel alloc]init];
    self.personDescribe.textColor = [UIColor lightGrayColor];
    self.personDescribe.font = [UIFont systemFontOfSize:15];
    [infoView addSubview:self.personDescribe];
    [self.personDescribe mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.voiceLabel.mas_bottom).offset(5);
        make.right.mas_equalTo(-10);
        make.height.mas_equalTo(((SCREEN_HEIGHT-SCREEN_WIDTH)/3-30-25)/2);
        make.left.equalTo(self.logo.mas_right).offset(10);
    }];
    UIView *smallSpace = [[UIView alloc]init];
    smallSpace.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:smallSpace];
    [smallSpace mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.height.mas_equalTo(5);
    }];
}
-(void)musicSliderAction:(UISlider*)slider{
    [[LXMusicPlay shareLXMusicPlay]playWithSliderChange:slider.value];
}
-(void)playListAction{
    LXMusicPlayerListVC  *list = [LXMusicPlayerListVC new];
    list.musicListArray = self.allArray;
    list.index = self.index;
    [self.navigationController pushViewController:list animated:YES];
}
-(void)historyAction{
    LXHistoryViewController *history = [LXHistoryViewController new];
    history.naviTitle = @"播放历史";
    [self.navigationController pushViewController:history animated:YES];
}
-(void)play{
    if (![[[NSUserDefaults standardUserDefaults]objectForKey:@"musicID"] isEqualToString:[NSString stringWithFormat:@"%ld",self.songId]]) {
        [self.playButton setImage:[UIImage imageNamed:@"toolbar_pause_n_p@2x.png"] forState:UIControlStateNormal];
        [[LXMusicPlay shareLXMusicPlay]play:self.songId];
        [self insertIntoDB];
        [[NSNotificationCenter defaultCenter]postNotificationName:@"playImage" object:self.allArray[self.index]];
        NSString *temp = [NSString stringWithFormat:@"%ld",self.songId];
        [[NSUserDefaults standardUserDefaults]setValue:temp forKey:@"musicID"];
    }
}
-(void)playAction{
    if ([[[LXMusicPlay shareLXMusicPlay]isPlayOrStop] isEqualToString:@"stop"]) {
        [self.playTimer invalidate];
        [[LXMusicPlay shareLXMusicPlay]stop];
        [[NSNotificationCenter defaultCenter]postNotificationName:@"musicStop" object:nil];
        [self.playButton setImage:[UIImage imageNamed:@"toolbar_play_n_p@2x.png"] forState:UIControlStateNormal];
    }else if ([[[LXMusicPlay shareLXMusicPlay]isPlayOrStop] isEqualToString:@"continue"]){
        self.playTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(Stack) userInfo:nil repeats:YES];
        [[LXMusicPlay shareLXMusicPlay]resume];
        [self.playButton setImage:[UIImage imageNamed:@"toolbar_pause_n_p@2x.png"] forState:UIControlStateNormal];
    }
}
-(void)btnAction{
    [self dismissViewControllerAnimated:YES completion:nil];
}
-(void)moreAction{
    NSLog(@"more");
}
-(void)frontButtonAction{
    [[LXMusicPlay shareLXMusicPlay]play:[[self.allArray objectAtIndex:--self.index] trackId]];
    [self changeImage:self.index];
    [self.playButton setImage:[UIImage imageNamed:@"toolbar_pause_n_p@2x.png"] forState:UIControlStateNormal];
    self.titleLabel.text = [[self.allArray objectAtIndex:self.index] title];
    if (self.index == 0) {
        [self.frontButton setBackgroundImage:[UIImage imageNamed:@"toolbar_prev_h_p@2x.png"] forState:UIControlStateNormal];
        self.frontButton.enabled = NO;
    }
    if (self.index == self.allArray.count-2) {
        [self.nextButton setBackgroundImage:[UIImage imageNamed:@"toolbar_next_n_p@2x.png"] forState:UIControlStateNormal];
        self.nextButton.enabled = YES;
    }
}

-(void)nextButtonAction{
    [[LXMusicPlay shareLXMusicPlay]play:[[self.allArray objectAtIndex:++self.index] trackId]];
    [self changeImage:self.index];
    self.titleLabel.text = [[self.allArray objectAtIndex:self.index] title];
    [self.playButton setImage:[UIImage imageNamed:@"toolbar_pause_n_p@2x.png"] forState:UIControlStateNormal];
    if (self.index == 1) {
        [self.frontButton setBackgroundImage:[UIImage imageNamed:@"toolbar_prev_n_p@2x.png"] forState:UIControlStateNormal];
        self.frontButton.enabled = YES;
    }
    if (self.index == self.allArray.count-1) {
        [self.nextButton setBackgroundImage:[UIImage imageNamed:@"toolbar_next_d_p@2x.png"] forState:UIControlStateNormal];
        self.nextButton.enabled = NO;
    }
}

-(void)changeImage:(NSInteger)index{
    [_midImage sd_setImageWithURL:[NSURL URLWithString:[[self.allArray objectAtIndex:index] coverLarge]] placeholderImage:[UIImage imageNamed:ImagePlaceHolder]];
    [_headImage sd_setImageWithURL:[NSURL URLWithString:[[self.allArray objectAtIndex:index] coverLarge]] placeholderImage:[UIImage imageNamed:ImagePlaceHolder]];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


@end
